<template>
    <div class="app-container">
        <el-form ref="queryParamsRef" :inline="true" :model="queryParams">
            <el-row :gutter="20">
                <el-col :span="6">
                    <el-form-item label="部门受案号-案管审批">
                        <el-input v-model="queryParams.casecode" clearable @clear="getTableDataLists" style="width: 15vw;"/>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="案件名称">
                        <el-input v-model="queryParams.name" 
                        clearable 
                        @clear="getTableDataLists" 
                        @keyup.enter.prevent="getTableDataLists"
                        style="width: 15vw;"
                        />
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item label="申请时间">
                        <el-date-picker
                            v-model="dateRange"
                            value-format="YYYY-MM-DD"
                            type="daterange"
                            range-separator="-"
                            start-placeholder="开始日期"
                            end-placeholder="结束日期"
                            style="width:13vw"
                        ></el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                    <el-form-item>
                        <el-button type="primary" @click="getTableDataLists">
                            <el-icon class="me-1">
                                <Search/>
                            </el-icon>
                            查询
                        </el-button>
                    </el-form-item>
                    <el-form-item>
                        <el-button @click="handleRest">
                            <el-icon class="me-1">
                                <Refresh/>
                            </el-icon>
                            重置
                        </el-button>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <el-divider class="mt-0 mb-3"/>

        <el-row class="mb-3">
            <el-col :span="24">
                <el-space>
                    <el-button
                        plain
                        type="primary"
                        @click="BatchApproval"
                    >
                        <el-icon class="me-2">
                            <Edit/>
                        </el-icon>
                        批量审批通过
                    </el-button>
                    <el-button
                        plain
                        type="danger"
                        @click="BatchReturn"
                    >
                        <el-icon class="me-2">
                            <EditPen/>
                        </el-icon>
                        批量审批退回
                    </el-button>
                </el-space>
            </el-col>
        </el-row>
        <el-table
            ref="TableDataRef"
            v-loading="loading"
            :data="TablesData"
            show-overflow-tooltip
            @selection-change="handleSelectionChange"
        >
            <el-table-column type="selection" width="55" />
            <el-table-column label="借阅单位" prop="name"/>
            <el-table-column label="申请借阅人" prop="peoplename"/>
            <el-table-column label="申请时间" prop="casetype"/>
            
            <el-table-column label="部门受案号" prop="userName"/>
            <el-table-column label="案件名称" prop="casetype"/>
            <el-table-column label="赃证物类别" prop="casetype"/>
            <el-table-column label="任务状态" prop="state" width="80">
                <template #default="scope">
                    <dict-tag :options="nj_anjian_status" :value="scope.row.state"/>
                </template>
            </el-table-column>
            <el-table-column fixed="right" align="center" label="操作" width="160">
                <template #default="scope">
                    <el-button
                        link size="small"
                        type="primary"
                        @click="Approval(scope.row)"
                        >
                        <el-icon class="me-1">
                            <Edit/>
                        </el-icon>
                        审批通过
                    </el-button>
                    <el-button
                        link size="small"
                        type="danger"
                        @click="Return(scope.row)"
                        >
                        <el-icon class="me-1">
                            <Edit/>
                        </el-icon>
                        退回
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination
            v-show="total > 0"
            :total="total"
            v-model:page="queryParams.pageNum"
            v-model:limit="queryParams.pageSize"
            @pagination="getTableDataLists"
        />
        <AddEditCase ref="AddEditCaseRef" @getCaseList="getTableDataLists" />
    </div>
</template>

<script setup>
const {proxy} = getCurrentInstance();
import AddEditCase from "@/components/Case/AddEditCase.vue";
// import {getCaseInfoList,getCaseInfoInfo,  deleteCaseInfo} from "@/api/CaseInfo/CaseInfo";
import PageEnum from "@/enum/PageEnum.js";

const {nj_anjian_type,nj_anjian_status} = proxy.useDict('nj_anjian_type', 'nj_anjian_status')

const AddEditCaseRef = ref({})
const loading = ref(false)

const dateRange = ref([])
const queryParams = ref({
    name: '',
    casecode: '',
    // 页码
    pageNum: 1,
    // 分页数量
    pageSize: PageEnum.SIZE
})

const total = ref(0)
const TableDataRef = ref()
const TablesData = ref([
    {name:'111',peoplename:"张三"},
    {name:'222',peoplename:"李四"},
    {name:'333',peoplename:"王五"},
])
const BatchList = ref([])

onMounted(() => {
    // getTableDataLists()
})

// 获取案件列表
const getTableDataLists = async () => {
    // loading.value = true
    // await getCaseInfoList(proxy.addDateRange(queryParams.value, dateRange.value)).then(res => {
    //     loading.value = false;
    //     TablesData.value = res.rows
    //     total.value = res.total;
    // });
}

// 批量选中
const handleSelectionChange = async (val) => {
    console.log(val)
    BatchList.value = val.map(item => item.name);  
}

// 审批通过   Approval
const Approval = async (row) => {
    console.log(row); // 输出选中的 name 数组
}
// 退回   Return
const Return = async (row) => {
    console.log(row); // 输出选中的 name 数组
}
// 批量通过   BatchApproval
const BatchApproval = async () => {
    console.log(BatchList.value); // 输出选中的 name 数组
}
// 批量退回   BatchReturn
const BatchReturn = async () => {
    console.log(BatchList.value); // 输出选中的 name 数组
}

// 重置搜索调解
const handleRest = () => {
    queryParams.value = {
        name: '',
        casecode: '',
    }
    getTableDataLists()
}
</script>

<style lang="scss" scoped>

</style>